<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
	public function authenticate()
	{
		$record=Usuario::model()->findByAttributes(array('usuario'=>$this->username));
		
		if($record===null)
            { 
                $this->errorCode=self::ERROR_USERNAME_INVALID;
            }
			 else if($record->clave!==$this->password)     // here I compare db password with password field
            { 
                $this->errorCode=self::ERROR_PASSWORD_INVALID;
            }
            else
            {  
                $this->setState('idUsuario',$record->idUsuario);
                //$this->setState('name', $record->name.' '.$record->lastname);
                $this->errorCode=self::ERROR_NONE;
            }
            return !$this->errorCode;
    }
}